# coding:utf-8
import datetime
import subprocess
import time
from datetime import datetime

import dingtalkchatbot.chatbot as cb


# 每n秒执行一次
def timer(n):
    while True:
        print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        dingding = dingRobot()
        dingding.dingStart()
        time.sleep(n)


class dingRobot():

    def __init__(self):
        self.url = "https://oapi.dingtalk.com/robot/send?access_token=d0cd26807d9901911ae7b5f6f8fc82e0eb2bc42ea2171b4605fef3f41cc05216"

    def getMessage(self):
        message = subprocess.getoutput("cat /root/moveTask/move2.log | grep 转移成功 | wc -l ")
        return message

    def dingStart(self):
        msg = self.getMessage()
        xiaoding = cb.DingtalkChatbot(self.url)
        xiaoding.send_text(msg=msg)


if __name__ == "__main__":
    # 5s
    timer(5)
